package hgin

import (
	"github.com/gin-gonic/gin"
	"html/template"
	"log/slog"
	"net/http"
)

// HTML 指定模板渲染HTML页面
func HTML(ctx *gin.Context, tpl *template.Template, name string, data any) {
	ctx.Header("Content-Type", "text/html;charset=UTF-8")
	ctx.Status(http.StatusOK)
	err := tpl.ExecuteTemplate(ctx.Writer, name, data)
	if err != nil {
		slog.Error("HTML Error:%s", err.Error())
		ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
	}
	ctx.Abort()
}
